package com.ivr.cm.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.ivr.cm.dao.IConfigBusinessDao;
import com.ivr.cm.util.BaseUtil;
import com.ivr.cm.vo.ConfigBusinessVo;

/**
 * 业务配置数据实现
 * @author liugeng
 * @date 2015-12-15
 * @version 1.0
 *
 */
public class ConfigBusinessDaoImpl extends JdbcDaoSupport implements IConfigBusinessDao {
	private static Logger logger = Logger.getLogger(ConfigBusinessDaoImpl.class);
	
	/**获得业务配置列表信息*/
	@SuppressWarnings("unchecked")
	@Override
	public List<ConfigBusinessVo> getConfigBusinessList() {
		String sql = "select sp_code, day_limit, month_limit,one_shot_limit,forbidden_province,forbidden_city,fee_type,fee_code,start_time,end_time,status from tb_ivr_config_business where status = 1";
		logger.info(String.format("获得业务配置列表[%s]", BaseUtil.logSQL(sql, null)));
		
		List<ConfigBusinessVo> configBusinessVoList = this.getJdbcTemplate().query(sql, rowMapper);
		if(configBusinessVoList != null && configBusinessVoList.size() > 0){
			return configBusinessVoList;
		}
		return null;
	}
	
	private ParameterizedRowMapper<ConfigBusinessVo> rowMapper = new ParameterizedRowMapper<ConfigBusinessVo>() {
		@Override
		public ConfigBusinessVo mapRow(ResultSet rs, int rowNum) throws SQLException {
			ConfigBusinessVo configBusinessVo = new ConfigBusinessVo();
			configBusinessVo.setSp_code(rs.getString("sp_code"));
			configBusinessVo.setDay_limit(rs.getInt("day_limit"));
			configBusinessVo.setMonth_limit(rs.getInt("month_limit"));
			configBusinessVo.setOne_shot_limit(rs.getInt("one_shot_limit"));
			configBusinessVo.setForbidden_province(rs.getString("forbidden_province"));
			configBusinessVo.setForbidden_city(rs.getString("forbidden_city"));
			configBusinessVo.setFee_type(rs.getInt("fee_type"));
			configBusinessVo.setFee_code(rs.getInt("fee_code"));
			configBusinessVo.setStatus(rs.getInt("status"));
			configBusinessVo.setStart_time(rs.getString("start_time"));
			configBusinessVo.setEnd_time(rs.getString("end_time"));
			return configBusinessVo;
		}
	};
}
